package com.example.android.commitcontent.ime.keyboard.adapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;

import com.example.android.commitcontent.ime.R;
import com.example.android.commitcontent.ime.cores.adapters.BaseRecyclerViewAdapter;
import com.example.android.commitcontent.ime.beans.HanZiCharacter;

import java.util.List;

/**
 * 拼音键盘候选字列表adapter
 */
public class PinYinWordsSuggestionAdapter extends BaseRecyclerViewAdapter<HanZiCharacter> {

    private OnWordItemClickListener onWordItemClickListener;

    public PinYinWordsSuggestionAdapter(Context context, int layoutResId, List<HanZiCharacter> strings) {
        super(context, layoutResId, strings);
    }

    @Override
    public void onHolderCreated(final BaseRecyclerViewAdapter.Holder holder) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onWordItemClickListener != null) {
                    onWordItemClickListener.onWordItemClick(holder.getAdapterPosition(), mDataList.get(holder.getAdapterPosition()));
                }
            }
        });
    }

    @Override
    protected void onBindData(@NonNull HanZiCharacter data, @NonNull Holder holder, int position) {
        holder.text(R.id.tv_title, data.hanzi);
    }


    public void setOnWordItemClickListener(OnWordItemClickListener onWordItemClickListener) {
        this.onWordItemClickListener = onWordItemClickListener;
    }

    public interface OnWordItemClickListener {
        void onWordItemClick(int position, HanZiCharacter word);
    }
}
